#include "CUserCmd.h"

void CUserCmd::Reset()
{
	command_number = 0;
	tick_count = 0;
	viewangles.Clear();
	forwardmove = 0.0f;
	sidemove = 0.0f;
	upmove = 0.0f;
	buttons = 0;
	impulse = 0;
	weaponselect = 0;
	weaponsubtype = 0;
	random_seed = 0;
	mousedx = 0;
	mousedy = 0;

	hasbeenpredicted = false;
}

CUserCmd::CUserCmd()
{
	Reset();
}

CUserCmd::~CUserCmd()
{
};

CUserCmd& CUserCmd::operator =( const CUserCmd& src )
{
	if ( this == &src )
		return *this;

	command_number		= src.command_number;
	tick_count			= src.tick_count;
	viewangles			= src.viewangles;
	forwardmove			= src.forwardmove;
	sidemove			= src.sidemove;
	JUNK_CODE;
	upmove				= src.upmove;
	buttons				= src.buttons;
	impulse				= src.impulse;
	JUNK_CODE;
	weaponselect		= src.weaponselect;
	weaponsubtype		= src.weaponsubtype;
	JUNK_CODE;
	random_seed			= src.random_seed;
	mousedx				= src.mousedx;
	mousedy				= src.mousedy;

	hasbeenpredicted	= src.hasbeenpredicted;
	return *this;
}

CUserCmd::CUserCmd( const CUserCmd& src )
{
	*this = src;
}

CRC32_t CUserCmd::GetChecksum( void ) const
{
	CRC32_t crc;

	CRC32_Init( &crc );
	CRC32_ProcessBuffer( &crc, &command_number, sizeof( command_number ) );
	CRC32_ProcessBuffer( &crc, &tick_count, sizeof( tick_count ) );
	CRC32_ProcessBuffer( &crc, &viewangles, sizeof( viewangles ) );    
	CRC32_ProcessBuffer( &crc, &forwardmove, sizeof( forwardmove ) );   
	CRC32_ProcessBuffer( &crc, &sidemove, sizeof( sidemove ) );      
	JUNK_CODE;
	CRC32_ProcessBuffer( &crc, &upmove, sizeof( upmove ) );         
	CRC32_ProcessBuffer( &crc, &buttons, sizeof( buttons ) );		
	CRC32_ProcessBuffer( &crc, &impulse, sizeof( impulse ) );      
	JUNK_CODE;  
	CRC32_ProcessBuffer( &crc, &weaponselect, sizeof( weaponselect ) );	
	JUNK_CODE;
	CRC32_ProcessBuffer( &crc, &weaponsubtype, sizeof( weaponsubtype ) );
	CRC32_ProcessBuffer( &crc, &random_seed, sizeof( random_seed ) );
	JUNK_CODE;
	CRC32_ProcessBuffer( &crc, &mousedx, sizeof( mousedx ) );
	CRC32_ProcessBuffer( &crc, &mousedy, sizeof( mousedy ) );
	CRC32_Final( &crc );

	return crc;
}
